package com.sanhe.rfmuscle.activity.work;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.sanhe.rfmuscle.App;
import com.sanhe.rfmuscle.databinding.ActivityWireBinding;
import com.sanhe.rfmuscle.event.Event;
import com.sanhe.rfmuscle.event.Num1Event;
import com.sanhe.rfmuscle.event.Time2Event;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class WireActivity extends BaseWorkActivity {

    ActivityWireBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.getApp().setIgnore(false);
        binding = ActivityWireBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.back.setOnClickListener(v -> sendTouchEvent((byte) 1, (byte) 0x1a));
        updateCard();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Num1Event event) {
        updateCard();
    }

    private void updateCard() {
//        if (Event.cardEvent.getValue() > 0) {
//            binding.img.setImageResource(R.mipmap.wire);
//        } else {
//            binding.img.setImageResource(R.mipmap.wire_ok);
//        }
        binding.tv.setText(Event.num1Event.getValue() + "");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Time2Event event) {
        updateTimeValue();
    }

    private void updateTimeValue() {
        binding.time.setText(Event.time2Event.getValue() + "");
    }
}
